﻿@inject AppConfiguration appConfiguration
@{
    var menuList = ViewData["menuList"] as List<Dictionary<string, object>>;
}
@model string
@functions{

    void CreateMenu(List<Dictionary<string, object>> menus, List<Dictionary<string, object>> menuAll)
    {
        //
        foreach (var item in menus)
        {
            var id = item["id"];
            var title = item["name"];
            var href = item["path"];
            var icon = item["icon"];
            var isClose = item["isClose"];
            var childless = item["children"] as List<Dictionary<string, object>>;
            var isFirst = menuAll.IndexOf(item) == 0;
            if (childless == null) continue;
            if (childless.Count > 0)
            {
                <el-submenu index="@(id)">

                    <template slot="title">
                        <i class="@icon"></i>
                        <span slot="title">@(title)</span>
                    </template>

                    @foreach (var children in childless)
                    {
                        id = children["id"];
                        title = children["name"];
                        href = children["path"];
                        icon = children["icon"];
                        isClose = children["isClose"];
                        childless = children["children"] as List<Dictionary<string, object>>;
                        if (childless == null) continue;
                        if (childless.Count > 0)
                        {
                            var menu = new List<Dictionary<string, object>>();
                            menu.Add(children);
                            CreateMenu(menu, menuAll);
                        }
                        else
                        {
                            <el-menu-item index="@(id)">
                                <i class="@icon"></i>
                                <span slot="title">@(title)</span>
                            </el-menu-item>
                        }
                    }
                </el-submenu>
            }
            else
            {
                <el-menu-item index="@(id)">
                    <i class="@icon"></i>
                    <span slot="title">@(title)</span>
                </el-menu-item>
            }
        }
    }

}
<div class="hzy-admin-logo">@(appConfiguration.AppTitle)</div>

@if (Model == "pc")
{
    <!--menu 菜单-->
    <el-menu :default-active="activeMenuKey" @@select="handleMenuSelect" :collapse="isCollapse" :background-color="menuTheme.backgroundColor" :text-color="menuTheme.textColor" :active-text-color="menuTheme.activeTextColor">
        @{CreateMenu(menuList, menuList);}
    </el-menu>
}
else
{
    <!--menu 菜单-->
    <el-menu :default-active="activeMenuKey" @@select="handleMenuSelect" :background-color="menuTheme.backgroundColor" :text-color="menuTheme.textColor" :active-text-color="menuTheme.activeTextColor">
        @{CreateMenu(menuList, menuList);}
    </el-menu>
}
